package com.ma.screens;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.ma.logica.AbstractScreen;
import com.ma.logica.Assets;
import com.ma.logica.LogicaJuego;

public class ScreenLoading extends AbstractScreen {
//http://mago-dev.com/?p=49
	private Stage stage;
	public Assets manager;
	private Texture background;
	private SpriteBatch batch;
	private LogicaJuego logicaJuego;

	public ScreenLoading(LogicaJuego logicaJuego) {
		super(logicaJuego);
		this.logicaJuego = logicaJuego;
	}

	@Override
	public void show() {
		// loading assets needed for loading screen
        logicaJuego.getAssetManager().load("data/imagenes/loading.png", Texture.class);
        // waiting for above assets to load
        logicaJuego.getAssetManager().finishLoading();
        // creating background that will be drawn while AssetManager loads
        background = logicaJuego.getAssetManager().get("data/imagenes/loading.png", Texture.class);
        batch = new SpriteBatch();
        
        Assets.instance.init(logicaJuego.getAssetManager());
        // start loading assets and wait until finished
//        logicaJuego.getAssetManager().finishLoading();
	}

	@Override
	public void render(float delta) {
		
		if (logicaJuego.getAssetManager().update()) {
			((Game) Gdx.app.getApplicationListener()).setScreen(new ScreenOne(logicaJuego));
        }
		
    	// drawing simple loading screen
        batch.begin();
        batch.draw(background, 0, 0,LogicaJuego.w, LogicaJuego.h);
        batch.end();
	}

	@Override
	public void resize(int width, int height) {

	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void hide() {
		// Al ocultar perdemos el procesador de entradas del stage.
		Gdx.input.setInputProcessor(null);
		logicaJuego.getAssetManager().unload("data/imagenes/loading.png");

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		stage.clear();
	}

}
